﻿using Microsoft.Extensions.Caching.Memory;

namespace SecretDemo
{
    public class Com
    {
        //缓存对象
        static readonly MemoryCache cache = new MemoryCache(new MemoryCacheOptions());
        //缓存存储方法
        public static void SaveToken(string token,User user)
        {
            cache.Set<User>(token, user);
        }
        /// <summary>
        /// 通过token从缓存里读取登录用户信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static User GetUserByToken(string token) {
            return cache.Get<User>(token);
        }
    }
}
